package com.hilihili.mapper;

import com.hilihili.domain.entity.District;
import com.hilihili.domain.entity.Tag;
import com.hilihili.domain.entity.Topic;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author machi
 * @date 2023/12/17
 */
@Mapper
public interface DistrictMapper {


    /**
     * 获取视频类型一级菜单
     *
     * @return {@link List}<{@link District}>
     */
    @Select("select id `value`,`name` label from district")
    List<District> getDistrict();

    /**
     * 通过一级菜单id查询二级菜单
     *
     * @param parentId
     * @return {@link List}<{@link District}>
     */
    @Select("select id `value`,`name` label from district_item where parent_id= #{parentId}")
    List<District> getDistrictItem(Integer parentId);

    /**
     * 获取推荐标签 由于es服务未开发 现在直接随机查询5条
     *
     * @return {@link List}<{@link District}>
     */
    @Select("select tag_id `value`,tag label from tag ORDER BY RAND() limit 5")
    List<Tag> getTag();

    /**
     * 获取推荐话题 由于es服务未开发 现在直接随机查询6条
     * @return {@link List}<{@link District}>
     */
    @Select("SELECT topic_id value,topic_name label FROM `topic` order by RAND() limit 6")
    List<Topic> getTopic();

    /**
     * 获取视频话题
     *
     * @param videoId 视频id
     * @return {@link Topic}
     */
    @Select("select t.topic_name  FROM topic t,video_topic vt where t.topic_id = vt.topic_id and vt.video_id = #{videoId}")
    String getTopicByVideoId(Long videoId);

    /**
     * 获取视频标签
     * @param videoId 视频id
     * @return {@link List}<{@link Tag}>
     */
    @Select("select t.tag  FROM tag t, video_tag vt where t.tag_id =vt.tag_id  and vt.video_id = #{videoId}")
    List<String> getTagByVideoId(Long videoId);
}
